package LeetcodeTest_eight;
//递减元素使数组呈锯齿状
public class movesToMakeZigzag
{
    public static void main(String[] args)
    {
        int num[]={7,4,8,9,7,7,5};
        System.out.println(solution.movesToMakeZigzag(num));
    }
}
class solution
{
    public static int movesToMakeZigzag(int[] nums)
    {
        int num[]=new int[nums.length];
        for(int i=0;i<nums.length;i++)
            num[i]=nums[i];
        return Math.min(mincount(0,nums),mincount(1,num));
    }
    public static int mincount(int i,int[] nums)
    {
        int min=0;
        while(i<=nums.length-1)
        {
            if(i-1>=0&&nums[i]<=nums[i-1])
            {
                min = min + nums[i - 1] - nums[i] + 1;
                nums[i - 1] = nums[i] - 1;
            }
            if(i+1<nums.length&&nums[i]<=nums[i+1])
            {
                min=min+nums[i+1]-nums[i]+1;
                nums[i+1]=nums[i]-1;
            }
            if(i==nums.length-1&&nums[i]<=nums[i-1])
            {
                min=min+nums[i-1]-nums[i]+1;
                nums[i-1]=nums[i]-1;
            }
            i=i+2;
        }
        return min;
    }
}